/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.shape;

import br.ufmg.dees.insane.util.IMatrix;


/**
*A class representing a shape function for the RMCIQ4 element.
*
*@author Samir
*@version 1.0
*@since 06/11/06
*/

public class RMCIT6 extends T6 {
	private static final long serialVersionUID = 1L;
	
	private double c1 = 0.5*(1-(1/Math.sqrt(3.0)));
	private double c2 = 0.5*(1+(1/Math.sqrt(3.0)));
	
	private double e1 = c1;
	private double e2 = c2;
	private double e3 = c2;
	private double e4 = c1;
	private double e5 = 0;
	private double e6 = 0;

	private double n1 = 0;
	private double n2 = 0;
	private double n3 = c1;
	private double n4 = c2;
	private double n5 = c2;
	private double n6 = c1;
	
    /* (non-Javadoc)
     * @see br.ufmg.dees.insane.shape.Shape2D#getType()
     */
    public String getType() {
        return "RMCIT6";
    }
    
    public IMatrix getAPT(double[] g, IMatrix cN){
		IMatrix APT = new IMatrix(2,12);
		APT.setZero();
		
    	double e = g[0];
		double n = g[1];
		
		IMatrix A = this.A(e,n);
		IMatrix P = this.P();
		IMatrix T = this.T();
		
		IMatrix aux = new IMatrix(A.getNumRow(),P.getNumCol());		aux.setZero();
		aux.mul(A,P);
		APT.mul(aux,T);
		
		return APT;
    }
    
    public IMatrix samplingPoints(){
    	IMatrix sp = new IMatrix(6,2);
    	sp.setZero();
    	
    	sp.setElement(0,0,e1);
    	sp.setElement(0,1,n1);
    	sp.setElement(1,0,e2);
    	sp.setElement(1,1,n2);
    	sp.setElement(2,0,e3);
    	sp.setElement(2,1,n3);
    	sp.setElement(3,0,e4);
    	sp.setElement(3,1,n4);
    	sp.setElement(4,0,e5);
    	sp.setElement(4,1,n5);
    	sp.setElement(5,0,e6);
    	sp.setElement(5,1,n6);
    	
    	return sp;
    }
    
    private IMatrix A(double e, double n){
    	IMatrix a = new IMatrix(2,6);
    	a.setZero();
    	
    	a.setElement(0,0,1);
    	a.setElement(0,1,e);
    	a.setElement(0,2,n);
    	
    	a.setElement(1,3,1);
    	a.setElement(1,4,e);
    	a.setElement(1,5,n);
    	
    	return a;
    }
    
    private IMatrix P(){
    	IMatrix p = new IMatrix(6,6);    	p.setZero();
    	IMatrix invP = new IMatrix(6,6);    	invP.setZero();
    	double a = Math.sqrt(2.0)/2.0;
    	
    	p.setElement(0,0,1);		p.setElement(0,1,e1);		p.setElement(0,2,n1);
    	
    	p.setElement(1,0,1);		p.setElement(1,1,e2);    	p.setElement(1,2,n2);
    	
    	p.setElement(2,0,-a);   	p.setElement(2,1,-a*e3);   	p.setElement(2,2,-a*n3);
    	p.setElement(2,3,a);    	p.setElement(2,4,a*e3);    	p.setElement(2,5,a*n3);
    	
    	p.setElement(3,0,-a);    	p.setElement(3,1,-a*e4);   	p.setElement(3,2,-a*n4);
    	p.setElement(3,3,a);    	p.setElement(3,4,a*e4);    	p.setElement(3,5,a*n4);
    	
    	p.setElement(4,3,1);    	p.setElement(4,4,e5);    	p.setElement(4,5,n5);
    	
    	p.setElement(5,3,1);    	p.setElement(5,4,e6);    	p.setElement(5,5,n6);
    	
    	invP = p.pseudoInverse();
    	
    	return invP;
    }

    private IMatrix T(){
    	IMatrix t = new IMatrix(6,12);    	t.setZero();
    	double a = Math.sqrt(2.0)/2.0;
    	
    	t.setElement(0,0,1);
    	t.setElement(1,2,1);
    	t.setElement(2,4,-a);
    	t.setElement(2,5,a);
    	t.setElement(3,6,-a);
    	t.setElement(3,7,a);
    	t.setElement(4,9,1);
    	t.setElement(5,11,1);
    	
    	return t;
    }
}

